class AutoUsersController < ApplicationController
  layout "blank_scaffold"
  before_filter :admin_required

  active_scaffold :auto_user do |config|
    config.list.per_page = 10
    config.columns = [:id, :username, :password, :title, :firstname, :lastname, :tel, :job_position, :office, :address, :admin_flag, :user_status, :register_code]
    config.list.columns.exclude :password, :tel, :job_position, :office, :address

    config.columns[:user_status].form_ui = :select
    config.columns[:user_status].options = {:options => ['Active','Deleted']}
    config.create.columns.exclude :id
    config.update.columns.exclude :id, :password
    config.show.columns.exclude :password
    config.list.sorting = {:id => 'ASC'}
    config.action_links.add 'reset_password', :label => 'ResetPass', :type => :member
  end

  def reset_password
    u = User.find(params[:id])
    u.password = Digest::SHA1.hexdigest(u.username)
    u.save
    render :text=>"Done!"
  end

  protected

  def before_create_save(record)
    record.password = Digest::SHA1.hexdigest(record.password)
  end
end
